package example.audio.artist;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import example.audio.track.Track;

@Entity
@Table(name="tb_artist")
public class Artist {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="artist_id")
	private int id;
	@Column
	private String name;
	@ManyToMany
	@JoinTable(name="tb_track_artist",
			   joinColumns={@JoinColumn(name="track_id")},
			   inverseJoinColumns={@JoinColumn(name="artist_id")})
	private Set<Track> Tracks = new HashSet<Track>(0);
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Set<Track> getTracks() {
		return Tracks;
	}
	public void setTracks(Set<Track> tracks) {
		Tracks = tracks;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Artist other = (Artist) obj;
		if (id != other.id)
			return false;
		return true;
	}
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Artist [id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append(", Tracks=");
		builder.append(Tracks);
		builder.append("]");
		return builder.toString();
	}
}
